package org.demo.warehouse.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.demo.warehouse.common.pojo.Record;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.demo.warehouse.common.pojo.RecordVo;
import org.demo.warehouse.common.pojo.User;
import org.demo.warehouse.common.pojo.WarehouseVo;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zgc
 * @since 2021-12-16
 */
public interface RecordMapper extends BaseMapper<Record> {

    @Select("select record.*,user.name as user_name,goods.name as goods_name from record " +
            "left join user on record.user_id=user.id " +
            "left join goods on record.goods_id=goods.id " +
            "${ew.customSqlSegment}")
    <E extends IPage<RecordVo>> E selectPageVo(E page, @Param(Constants.WRAPPER) Wrapper<Record> queryWrapper);

    @Select("select date_format(create_time, '%Y-%m-%d') `key`, sum(sum) `value`" +
            "from record where type = #{type} " +
            "group by date_format(create_time, '%Y-%m-%d')")
    List<Map<String, Object>> statistic(Integer type);
}
